//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
    //LOADING POPUP
    //Click the button event!
    $("#button").click(function(){
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });
    $("#popupContactOpen").click(function(){
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });
})
//CLOSING POPUP
//Click the x event!
$("#popupContactClose").click(function(){
    disablePopup();
});
//Click out event!
$("#backgroundPopup").click(function(){
    disablePopup();
});
//Press Escape event!
$(document).keypress(function(e){
    if(e.keyCode==27 && popupStatus==1){
        disablePopup();
    }
});



function clearForms(){
    var type = null;
    for (var x=0; x<document.forms.length; x++){
        for (var y=0; y<document.forms[x].elements.length; y++){
            type = document.forms[x].elements[y].type
            switch(type){
                case "text":
                case "textarea":
                case "password":
                    document.forms[x].elements[y].value = "";
                    break;
                case "radio":
                case "checkbox":
                    document.forms[x].elements[y].checked = "";
                    break;
                case "select-one":
                    document.forms[x].elements[y].options[0].selected = true;
                    break;
                case "select-multiple":
                    for (z=0; z<document.forms[x].elements[y].options.length; z++){
                        document.forms[x].elements[y].options[z].selected = false;
                    }
                    break;
            }
        }
    }
}